class Ruiqu::ContactInfosController < Ruiqu::BaseController
  before_action :set_store, only: [:new, :create, :show, :edit, :update]
  def new
    @contact_info = ContactInfo.new()
  end

  def create
    @contact_info = ContactInfo.new(contact_params)
    if @contact_info.save
      redirect_to ruiqu_store_contact_info_path, notice: "Store info was successful!"
    else
      redirect_to new_ruiqu_store_contact_info_path, notice: "I'm sorry that fails"
    end
  end

  def show
    if !@store.contact_info.present?
      redirect_to new_ruiqu_store_contact_info_path
    end
  end

  def edit
    @contact_info  = @store.contact_info
  end

  def update
    @contact_info = @store.contact_info
    @contact_info.update!(contact_params)
    redirect_to ruiqu_store_contact_info_path
  end

  private
  def set_store
    @store = current_store
  end

  def contact_params
    params.require(:contact_info).permit(
      :store_id,
      :name,
      :phone_number,
      :tel_phone,
      :wechat,
      :email,
      :qq
    )
  end
end
